home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / checkbox / registries / gconf.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  2.9 KB  |  100 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import re
  5. from checkbox.lib.conversion import string_to_type
  6. from checkbox.properties import Path, String
  7. from checkbox.registries.command import CommandRegistry
  8. from checkbox.registries.data import DataRegistry
  9.  
  10. class SourceRegistry(DataRegistry):
  11.     
  12.     def items(self):
  13.         items = []
  14.         lines = []
  15.         id = None
  16.         depth = None
  17.         for line in self.split('\n'):
  18.             if not line:
  19.                 continue
  20.             
  21.             match = re.match('(\\s+(\\/)?)(.+)', line)
  22.             if not match:
  23.                 lines[-1] += line
  24.                 continue
  25.             
  26.             space = len(match.group(1).rstrip('/'))
  27.             if depth is None:
  28.                 depth = space
  29.             
  30.             if space > depth:
  31.                 lines.append(line)
  32.                 continue
  33.             if match.group(2) is not None:
  34.                 if id is not None:
  35.                     value = SourceRegistry('\n'.join(lines))
  36.                     lines = []
  37.                     items.append((id, value))
  38.                 
  39.                 id = match.group(3).split('/')[-1].rstrip(':')
  40.                 continue
  41.             (key, value) = match.group(3).split(' = ', 1)
  42.             if value == '(no value set)':
  43.                 value = None
  44.             else:
  45.                 match = re.match('\\[([^\\]]*)\\]', value)
  46.                 if match:
  47.                     list_string = match.group(1)
  48.                     if len(list_string):
  49.                         value = list_string.split(',')
  50.                     else:
  51.                         value = []
  52.                 else:
  53.                     value = string_to_type(value)
  54.             items.append((key, value))
  55.         
  56.         if lines:
  57.             value = SourceRegistry('\n'.join(lines))
  58.             items.append((id, value))
  59.         
  60.         return items
  61.  
  62.  
  63.  
  64. class GconfRegistry(CommandRegistry):
  65.     '''Registry for gconf information.
  66.  
  67.     Each item contained in this registry consists of the udi as key and
  68.     the corresponding device registry as value.
  69.     '''
  70.     source = Path(default = '~/.gconf')
  71.     command = String(default = 'gconftool-2 -R / --config-source xml:readwrite:$source')
  72.     
  73.     def __init__(self, *args, **kwargs):
  74.         super(GconfRegistry, self).__init__(*args, **kwargs)
  75.         self.command = self.command.replace('$source', self.source)
  76.  
  77.     
  78.     def items(self):
  79.         items = []
  80.         key = None
  81.         lines = []
  82.         for line in self.split('\n'):
  83.             if line.startswith(' /'):
  84.                 if lines:
  85.                     value = SourceRegistry('\n'.join(lines))
  86.                     items.append((key, value))
  87.                 
  88.                 key = line.strip().lstrip('/').rstrip(':')
  89.                 continue
  90.             lines.append(line)
  91.         
  92.         if lines:
  93.             value = SourceRegistry('\n'.join(lines))
  94.             items.append((key, value))
  95.         
  96.         return items
  97.  
  98.  
  99. factory = GconfRegistry
  100.